/**
 * Created by ren on 05/04/2017.
 */
'use strict';
import {combineReducers} from 'redux';
import {
  CUT_TAB,
  UPDATE_NICKNAME,
  SELECT_BRAND,
  CANCEL_BRAND,
  FILTER_ORDER,
  CANCEL_FILTER_ORDER,
  CHECKLOGIN,
  CHECKNOTLOGIN,
  RESET_BRAND,
  UPDATE_SEX,
  UPDATE_BIRTHDAY,
  SELECT_COUNTRY,
  CANCEL_COUNTRY,
  RESET_COUNTRY,
  ORDERDATA_LOADED,
  ORDERDATA_NOTLOAD
} from '../actions'
const initialState = 'checkOrder';

function cutTab(state = initialState, action) {
  switch (action.type) {
    case CUT_TAB:
      return action.title
    default:
      return state
  }
}
const initialNickName = ''
function updateNickName(state = initialNickName, action) {
  switch (action.type) {
    case UPDATE_NICKNAME:
      return action.nickName
    default:
      return state
  }
}
const initialSex = ''
function updateSex(state = initialSex, action) {
  switch (action.type) {
    case UPDATE_SEX:
      return action.sex
    default:
      return state
  }
}
const initialBirthday = ''
function updateBirthday(state = initialBirthday, action) {
  switch (action.type) {
    case UPDATE_BIRTHDAY:
      return action.birthday
    default:
      return state
  }
}
const initialBrandIdArray = []
function selectBrand(state = initialBrandIdArray, action) {
  switch (action.type) {
    case SELECT_BRAND:
      return [
        ...state,
        action.brandId
      ]
    case CANCEL_BRAND:
      return state.filter((item) => {
        return item !== action.brandId
      })
    case RESET_BRAND:
      return []
    default:
      return state
  }
}
const initialCountryIdArray = []
function selectCountry(state = initialCountryIdArray, action) {
  switch (action.type) {
    case SELECT_COUNTRY:
      return [
        ...state,
        action.countryId
      ]
    case CANCEL_COUNTRY:
      return state.filter((item) => {
        return item !== action.countryId
      })
    case RESET_COUNTRY:
      return []
    default:
      return state
  }
}
const initialIsFilter = false
function filterOrder(state = initialIsFilter, action) {
  switch (action.type) {
    case FILTER_ORDER:
      return true
    case CANCEL_FILTER_ORDER:
      return false
    default:
      return state
  }
}

const initialLoginStatus = false
function loginStatus(state = initialLoginStatus, action) {
  switch (action.type) {
    case CHECKLOGIN:
      return true
    case CHECKNOTLOGIN:
      return false
    default:
      return state
  }
}
const initialOrderIsLoad = false
function OrderIsLoad(state = initialOrderIsLoad, action) {
  switch (action.type) {
    case ORDERDATA_LOADED:
      return true
    case ORDERDATA_NOTLOAD:
      return false
    default:
      return state
  }
}
const app = combineReducers({
  cutTab,
  updateNickName,
  selectBrand,
  filterOrder,
  loginStatus,
  updateSex,
  updateBirthday,
  selectCountry,
  OrderIsLoad
})
export default app;